#include "bullet.h"

Bullet::Bullet()
{
    //加载子弹资源
    m_Bullet.load(BULLET_PATH);

    //子弹坐标初始化
    m_X = GAME_WIDTH * 0.5 - m_Bullet.width() * 0.5;
    m_Y = GAME_HEIGHT;

    //子弹移动速度
    m_Speed = BULLET_SPEED;

    //子弹闲置
    m_Free = true;

    //子弹的矩形边框
    m_Rect.setWidth(m_Bullet.width());
    m_Rect.setHeight(m_Bullet.height());
    m_Rect.moveTo(m_X, m_Y);
}


/* 更新子弹坐标 */
void Bullet::updatePosition()
{
    //如果子弹闲置不更新
    if(m_Free)
    {
        return;
    }
    //子弹Y坐标减
    m_Y -= m_Speed;
    m_Rect.moveTo(m_X, m_Y);

    //如果子弹射出屏幕更新为闲置
    if(m_Y <= -m_Bullet.height())
    {
        m_Free = true;
    }
}












